package com.ruoyi.web.controller.system;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PremaidFood;
import com.ruoyi.system.service.IPremaidFoodService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 预制菜品类管理Controller
 * 
 * @author liukangzu
 * @date 2025-04-17
 */
@RestController
@RequestMapping("/system/food")
public class PremaidFoodController extends BaseController
{
    @Autowired
    private IPremaidFoodService premaidFoodService;

    /**
     * 查询预制菜品类管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:food:list')")
    @GetMapping("/list")
    public TableDataInfo list(PremaidFood premaidFood)
    {
        startPage();
        List<PremaidFood> list = premaidFoodService.selectPremaidFoodList(premaidFood);
        return getDataTable(list);
    }

    /**
     * 导出预制菜品类管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:food:export')")
    @Log(title = "预制菜品类管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PremaidFood premaidFood)
    {
        List<PremaidFood> list = premaidFoodService.selectPremaidFoodList(premaidFood);
        ExcelUtil<PremaidFood> util = new ExcelUtil<PremaidFood>(PremaidFood.class);
        util.exportExcel(response, list, "预制菜品类管理数据");
    }

    /**
     * 获取预制菜品类管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:food:query')")
    @GetMapping(value = "/{premaidFoodId}")
    public AjaxResult getInfo(@PathVariable("premaidFoodId") Integer premaidFoodId)
    {
        return success(premaidFoodService.selectPremaidFoodByPremaidFoodId(premaidFoodId));
    }

    /**
     * 新增预制菜品类管理
     */
    @PreAuthorize("@ss.hasPermi('system:food:add')")
    @Log(title = "预制菜品类管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PremaidFood premaidFood)
    {
        return toAjax(premaidFoodService.insertPremaidFood(premaidFood));
    }

    /**
     * 修改预制菜品类管理
     */
    @PreAuthorize("@ss.hasPermi('system:food:edit')")
    @Log(title = "预制菜品类管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PremaidFood premaidFood)
    {
        return toAjax(premaidFoodService.updatePremaidFood(premaidFood));
    }

    /**
     * 删除预制菜品类管理
     */
    @PreAuthorize("@ss.hasPermi('system:food:remove')")
    @Log(title = "预制菜品类管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{premaidFoodIds}")
    public AjaxResult remove(@PathVariable Integer[] premaidFoodIds)
    {
        return toAjax(premaidFoodService.deletePremaidFoodByPremaidFoodIds(premaidFoodIds));
    }

    /**
     * 上下架预制菜品类管理
     */
    @PreAuthorize("@ss.hasPermi('system:food:top')")
    @Log(title = "预制菜品类管理", businessType = BusinessType.UPDATE)
    @PutMapping("/top")
    public AjaxResult top(@RequestParam String premaidFoodIds)
    {
        Integer[] ids = Arrays.stream(premaidFoodIds.split(","))
                .map(Integer::valueOf)
                .toArray(Integer[]::new);

        return toAjax(premaidFoodService.topPremaidFoodByPremaidFoodIds(ids));
    }
}
